<?php include '../../../entries/restful.php';
/**
 *  维修统计
 */
class Surface extends Restful{

    public function action(){

        $user = json_decode($this->session->getItem('user'),true);
        $user_id = $user['id'];
        $cmt_id = $user['cmt_id'];

        $sql = 'select state from prop_fix where worker_id = ? and cmt_id = ? order by id desc';
        $arg = [$user_id,$cmt_id];

        $info = Mdb::query(MDB_MAIN,$sql,$arg);

        $make = 0;
        $success = 0;
        $wait = 0;
        foreach($info as $val){
            if($val['state'] == 0) $wait += 1;
            if($val['state'] == 1) $make += 1;
            if($val['state'] == 2) $success += 1;
        }

        return Res::ok(["wait" => $wait,"make" => $make , "success" => $success]);
    }
}

new Surface();